package com.juyu.miliao.api.rabbitMQ;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.juyu.miliao.common.constant.BillDetailBeansMqKey;
import com.juyu.miliao.common.constant.UserWalletBeansSumMqKey;
import com.juyu.miliao.common.domain.dto.BillDetailBeansDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Auther: 卜加超
 * @Date: 2019/7/13 11:03
 * @Description:
 */
@Component
@Slf4j
public class BillDetailBeansMq {
    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    private ObjectMapper objectMapper;

    public void getBillDetailBeansMq(BillDetailBeansDTO beansDTO){
        try {
            if (beansDTO != null) {
                amqpTemplate.convertAndSend(BillDetailBeansMqKey.EXCHANGE_KEY,
                        BillDetailBeansMqKey.CreateCommontBillDetailBeansMQKEY.ROUTING_KEY,
                        objectMapper.writeValueAsString(beansDTO));
            }
        }catch (Exception ex){
            log.info("添加寻豆账单信息放入队列失败：{}", beansDTO);
        }
    }
}
